(function () {
    if (Array.prototype.contains === undefined) {
        Array.prototype.contains = function (item) {
            for (var i = 0; i < this.length; ++i) {
                if (this[i] === item) {
                    return true;
                }
            }
            return false;
        };
    }
    //if (Array.prototype.join === undefined) {
    Array.prototype.join = function (sep) {
        sep = sep || '';
        var result = '';
        for (var i = 0; i < this.length; ++i) {
            if (i > 0) {
                result += sep;
            }
            if (this[i] !== null && this[i] !== undefined) {
                result += this[i].toString();
            }
        }
        return result;
    };
    //}
    if (Array.prototype.clear === undefined) {
        Array.prototype.clear = function () {
            this.length = 0;
        };
    }
    if (Array.prototype.size === undefined) {
        Array.prototype.size = function () {
            return this.length;
        };
    }
    if (Array.prototype.get === undefined) {
        Array.prototype.get = function (index) {
            return this[index];
        };
    }
    if (Array.prototype.remove === undefined) {
        Array.prototype.remove = function (item) {
            var index = this.indexOf(item);
            if (index >= 0) {
                this.removeAt(index);
            }
            return this;
        };
    }
    if (Array.prototype.removeAt === undefined) {
        Array.prototype.removeAt = function (index) {
            if (index >= 0 && index < this.length) {
                var item = this[index];
                this.splice(index, 1);
                return item;
            } else {
                return undefined;
            }
        };
    }
    if (Array.prototype.insertAt === undefined) {
        Array.prototype.insertAt = function (index, item) {
            if (index >= this.length) {
                this.push(item);
            } else {
                this.splice(index, 1, item, this[index]);
            }
        };
    }
    if (Array.prototype.addAll === undefined) {
        Array.prototype.addAll = function (items) {
            for (var i = 0; i < items.length; ++i) {
                this.push(items[i]);
            }
            return this;
        };
    }
    if (Array.prototype.map === undefined) {
        Array.prototype.map = function (callback) {
            var result = [];
            for (var i = 0; i < this.length; ++i) {
                result.push(callback(this[i], i));
            }
            return result;
        };
    }
    if (Array.prototype.compact === undefined) {
        Array.prototype.compact = function () {
            var result = [];
            for (var i = 0; i < this.length; ++i) {
                if (this[i] !== undefined && this[i] !== null) {
                    result.push(this[i]);
                }
            }
            return result;
        };
    }
    if (Array.prototype.subItems === undefined) {
        Array.prototype.subItems = function (start, end) {
            if (end === undefined) {
                end = 0;
            }
            if (start === undefined) {
                start = 0;
            }
            if (end == 0) {
                end = this.length;
            }
            var result = [];
            for (var i = start; i < end; ++i) {
                if (i >= 0 && i < this.length) {
                    result.push(this[i]);
                }
            }
            return result;
        };
    }
    ['Arguments', 'Function', 'String', 'Number', 'Date', 'RegExp', 'Error'].forEach(function (name) {
        window['is' + name] = function (obj) {
            return Object.prototype.toString.call(obj) === '[object ' + name + ']';
        };
    });
    window.getParameterByName = function (name) {
        name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
        var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
            results = regex.exec(location.search);
        return results === null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));
    };
})();